package com.sec.etech.employeesync.sapquery.strategy;

import com.alibaba.fastjson.JSONObject;
import com.sec.etech.employeesync.sapquery.util.SapParamsBuilder;
import org.apache.commons.lang3.StringUtils;
import org.openbpm.base.api.exception.BusinessException;

import java.util.ArrayList;
import java.util.List;

public class AccountQueryStrategy implements QueryStrategy {
    @Override
    public List<JSONObject> buildSapParams(JSONObject businessParams) {
        List<JSONObject> sapParamsList = new ArrayList<>();
        JSONObject sapParams = new JSONObject();

        String account = businessParams.getString("account");
        String code = businessParams.getString("code");

        if (StringUtils.isBlank(account)) {
            throw new BusinessException("请先选择要更新的员工");
        }

        if (StringUtils.isBlank(code)) {
            throw new BusinessException("找不到对应公司，请联系管理员");
        }

        sapParams.put("IT_PERNR", SapParamsBuilder.buildItPernr(account));
        sapParams.put("I_WERKS", code);
        sapParamsList.add(sapParams);
        return sapParamsList;
    }
}
